package com.example.wechat;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Activity1 extends AppCompatActivity {
    Button button1,button2;
    TextView textView3;
    View view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_1);
        button1=findViewById(R.id.button1);
        button2=findViewById(R.id.button2) ;
        textView3=findViewById(R.id.textview1);
        Log.d("jd","1:onCreat...");
        button1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Activity1.this, Activity2.class);//做一个跳转
                intent.putExtra("name", "jd");
                intent.putExtra("age", 21);
                Bundle bundle=new Bundle();//打包数据绑定
                bundle.putString("name","ja");
                bundle.putInt("age",12);
//                bundle.putBundle();//也是数据嵌套
                //1跳2，并且给1一个结束的返回值
                //1给2一个请求码 2返回的值有button1或button2的
                intent.putExtras(bundle);//转发功能 数据分发
                startActivity(intent);
            }
        });
        ActivityResultLauncher launcher1=registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
                new ActivityResultCallback<ActivityResult>() {
            @Override
            public void onActivityResult(ActivityResult result) {
                if (result.getResultCode() == 666) {
                    String str = result.getData().getStringExtra("result");
                    textView3.setText(str);
                }
            }
        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent3=new Intent(Activity1.this, Activity3.class);
                        launcher1.launch(intent3);

            }
        });

    }




    @Override
    protected void onPostResume() {
        super.onPostResume();
        Log.d("jd","1:onPostResume...");
    }
    @Override
    protected void onResume() {
        super.onResume();
        Log.d("jd","1:onResume...");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("jd","1:onStart...");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d("jd","1:onRestart...");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("jd","1:onPause...");
    } @Override
    protected void onStop() {
        super.onStop();
        Log.d("jd","1:onStop...");
    }

}